﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Tauren.File.Infrastructure.Common;
using Tauren.File.Service.FileBLL;
using Tauren.File.Service.FileFolderBLL;

namespace Tauren.File.Core.Controllers
{
    /// <summary>
    /// 文件夹
    /// </summary>
    [Route("api/file")]
    [ApiController]
    public class FileController : ControllerBase
    {
        private IFileService service;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        public FileController(IFileService service)
        {
            this.service = service;
        }

        /// <summary>
        /// 新增数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/add"), ApiVersion("1.0")]
        public IActionResult Add([FromBody] Entity.Input.Files_Input input) => service.Add(input).ToJsonResult();


        /// <summary>
        /// 编辑信息
        /// </summary>
        /// <param name="input">单位信息</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/edit"), ApiVersion("1.0")]
        public IActionResult Editor([FromBody] Entity.Input.Files_Input input) => service.Edit(input).ToJsonResult();

        /// <summary>
        /// 获取单个信息数据
        /// </summary>
        /// <param name="id">单位实体id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/get/{id}"), ApiVersion("1.0")]
        public IActionResult Get([FromRoute] int id) => service.Get(id).ToJsonResult();

        /// <summary>
        /// 删除信息
        /// </summary>
        /// <param name="id">单位实体id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/del/{id}"), ApiVersion("1.0")]
        public IActionResult Delete([FromRoute] int id) => service.Delete(id).ToJsonResult();
        /// <summary>
        /// 启用??
        /// </summary>
        /// <param name="id">单位ID</param> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/enable/{id}"), ApiVersion("1.0")]
        public IActionResult Enable(int id) => service.Enable(id).ToJsonResult();
        /// <summary>
        /// 获取字段数据
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/config/{type}"), ApiVersion("1.0")]
        public IActionResult Config([FromRoute] string type) => service.Config(type).ToJsonResult(true);
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="folderId">文件夹id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/upload/{folderId}"), ApiVersion("1.0")]
        public IActionResult Upload([FromRoute] long folderId, [FromForm] IFormFile file) => service.Upload(file, folderId).ToJsonResult(true);
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="folderId">文件夹id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/getfiles"), ApiVersion("1.0")]
        public IActionResult GetFiels([FromBody] string[] ids) => service.GetFiles(ids).ToJsonResult(true);

        /// <summary>
        /// 上传取消时删除文件
        /// </summary>
        /// <param name="folderId">文件夹id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/uploaddel"), ApiVersion("1.0")]
        public IActionResult UploadDelete([FromBody] string[] ids) => service.UploadDelete(ids).ToJsonResult(true);
        /// <summary>
        /// 分页获取列表
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/pages"), ApiVersion("1.0")]
        public IActionResult Pages([FromBody] Entity.Global.QueryModel queryModel) => service.Pages(queryModel).ToJsonResult();
        /// <summary>
        /// 保存头像
        /// </summary>
        /// <param name="fileid">头像ID</param>
        /// <param name="empid">员工ID</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/savephoto/{fileid}/{empid}"), ApiVersion("1.0")]
        public IActionResult SavePhoto([FromRoute] long fileid,[FromRoute] int empid) => service.SavePhoto(fileid,empid).ToJsonResult(true);

        /// <summary>
        /// 获取头像
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/photo/{empid}"), ApiVersion("1.0")]
        public IActionResult Photo([FromRoute] int empid) => service.GetPhoto(empid).ToJsonResult(true);

    }
}
